package com.orange.core.pojo.entity.product;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.orange.core.pojo.entity.IIntIdModel;
import com.orange.core.pojo.entity.IOperatorModel;
import com.orange.core.validator.group.Update;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@TableName(autoResultMap = true)
public class CreditProduct implements IIntIdModel<CreditProduct>, IOperatorModel<CreditProduct> {

    @NotNull(message = "请求参数不合法", groups = {Update.class})
    @TableId(type = IdType.AUTO)
    private @With Integer id;

    /**
     * 商品分类
     */
    @NotNull(message = "请选择分类")
    private Integer categoryId;

    /**
     * 商户id
     */
    @NotNull(message = "请选择品牌")
    private Integer shopId;

    /**
     * 商品名
     */
    @NotBlank(message = "请输入商品名")
    private String name;

    @NotBlank(message = "请上传封面图")
    private String coverImage;

    /**
     * 图片
     */
    @NotEmpty(message = "请上传商品图片")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<String> pics;

    /**
     * 积分
     */
    @NotNull(message = "请输入兑换积分")
    private Integer credit;

    /**
     * 价格
     */
    @NotNull(message = "请输入价格")
    private BigDecimal price;

    /**
     * 领取门店
     */
    @TableField(exist = false)
    private String shopName;

    /**
     * 领取门店地址
     */
    @TableField(exist = false)
    private String shopAddress;

    /**
     * 描述
     */
    private String description;

    /**
     * 上架状态：1上架，0下架
     */
    private Integer shelf;

    /**
     * 库存
     */
    @NotNull(message = "请输入库存")
    private Integer stock;

    @TableLogic
    private Long del;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime createTime;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @TableField(fill = FieldFill.INSERT)
    private Integer createBy;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime updateTime;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Integer updateBy;
}
